package gui;

import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.JScrollPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.border.TitledBorder;

public class Instructores extends JFrame {

	private JPanel contentPane;
	private JTextField textField;
	private JLabel lblResultadoBusqueda;
	private JTable table;
	private JScrollPane scrollPane;
	private JButton btnSalir;
	private JButton btnCrear;
	private JButton btnEditar;
	private JPanel panel;
	private InstructoresEditarCrear instructoresEditarCrear=null;
	private Instructores instructoresPadre;
	InstructoresEditarCrear inseditar=null;
	
	
	public void nullInstructoresEditarCrear()
	{
		instructoresEditarCrear=null;
	}
	
	/**
	 * Launch the application.
	
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Instructores frame = new Instructores(null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	*/

	/**
	 * Create the frame.
	 * @param padre 
	 */
	public Instructores(Principal padre) {
		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent e){
				padre.nullinstructores();
			}
		});
		instructoresPadre=this;
		setTitle("Instructores");
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		setBounds(330, 330, 450, 429);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		panel = new JPanel();
		panel.setBorder(new TitledBorder(null, "Busqueda", TitledBorder.LEADING, TitledBorder.TOP, null, null));
		panel.setBounds(10, 11, 412, 43);
		contentPane.add(panel);
		panel.setLayout(null);
		
		JLabel lblClave = new JLabel("Nombre:");
		lblClave.setBounds(6, 19, 65, 14);
		panel.add(lblClave);
		
		textField = new JTextField();
		textField.setBounds(81, 16, 325, 20);
		panel.add(textField);
		textField.setColumns(10);
		
		scrollPane = new JScrollPane();
		scrollPane.setBounds(10, 90, 414, 245);
		contentPane.add(scrollPane);
		
		table = new JTable();
		scrollPane.setViewportView(table);
		table.setModel(new DefaultTableModel(
			new Object[][] {
			},
			new String[] {
				"Nombre", "Apellido", "Telefono", "Cursadas"
			}
		) {
			boolean[] columnEditables = new boolean[] {
				false, false, true, true
			};
			public boolean isCellEditable(int row, int column) {
				return columnEditables[column];
			}
		});
		table.getColumnModel().getColumn(0).setResizable(false);
		table.getColumnModel().getColumn(1).setResizable(false);
		
		lblResultadoBusqueda = new JLabel("Resultado de la Busqueda:");
		lblResultadoBusqueda.setBounds(10, 65, 170, 14);
		contentPane.add(lblResultadoBusqueda);
		
		btnSalir = new JButton("Salir");
		btnSalir.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				padre.nullinstructores();
				dispose();
			}
		});
		btnSalir.setBounds(352, 357, 72, 23);
		contentPane.add(btnSalir);
		
		btnCrear = new JButton("Crear");
		btnCrear.setBounds(253, 357, 89, 23);
		contentPane.add(btnCrear);
		
		btnEditar = new JButton("Editar");
		btnEditar.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				if(inseditar==null)
				inseditar = new InstructoresEditarCrear(instructoresPadre);
			inseditar.setVisible(true);
			}
		});
		btnEditar.setBounds(154, 357, 89, 23);
		contentPane.add(btnEditar);
	}

}